<template>
  <div class="favorite-card">
    <div class="favorite-card__cover">
      <img :src="favorite.videos.length ? UrlUtil.getFullImgUrl(favorite.videos[0].videoCover):null" :alt="favorite.name">
      <div class="video-count">
        {{ formatCount(favorite.videos.length) }}个视频
      </div>
    </div>
    <div class="favorite-card__content">
      <h3 class="title" :title="favorite.name">{{ favorite.name }}</h3>
    </div>
  </div>
</template>

<script setup>
import UrlUtil from "@/utils/Url/Url.js";

defineProps({
  favorite: {
    type: Object,
    required: true,
  }
})

function formatCount(count) {
  if (count >= 10000) {
    return (count / 10000).toFixed(1) + '万'
  }
  return count
}
</script>

<style lang="less" scoped>
.favorite-card {
  cursor: pointer;

  &:hover {
    .title {
      color: #00aeec;
    }

    .favorite-card__cover img {
      transform: scale(1.04);
    }
  }

  .favorite-card__cover {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    background-color: #f3f3f3;
    aspect-ratio: 16 / 10;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      transition: transform 0.3s;
    }

    .video-count {
      position: absolute;
      bottom: 5px;
      right: 5px;
      padding: 2px 8px;
      font-size: 12px;
      color: #fff;
      background: rgba(0, 0, 0, 0.7);
      border-radius: 10px;
    }
  }

  .favorite-card__content {
    padding: 8px 0;

    .title {
      margin: 0;
      font-size: 16px;
      font-weight: 500;
      line-height: 1.5;
      color: #18191c;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }
}
</style>
